# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=hidapi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.14.0
pkgrel=1
pkgdesc="Library for communicating with USB and Bluetooth HID devices (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://github.com/libusb/hidapi"
license=('spdx:GPL-3.0-or-later' 'spdx:BSD-3-Clause' 'custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc" "${MINGW_PACKAGE_PREFIX}-autotools")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
source=("https://github.com/libusb/hidapi/archive/${_realname}-${pkgver}.tar.gz")
sha256sums=('a5714234abe6e1f53647dd8cba7d69f65f71c558b7896ed218864ffcf405bcbd')

prepare() {
  cd ${srcdir}/${_realname}-${_realname}-${pkgver}

  autoreconf -vif
}

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"
  ../${_realname}-${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-testgui
  make
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  install -Dm644 ${srcdir}/${_realname}-${_realname}-${pkgver}/LICENSE{-bsd,-gpl3,-orig,}.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/
}
